/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.brainstretch.recommend;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.brainstretch.models.quizzes.Category;

/**
 *
 * @author mrodaitis
 */
@Entity
public class CategoryWeight implements Serializable {
    private static final long serialVersionUID = 1L;
    private static final double MIN_WEIGHT = 0.0;
    private static final double MAX_WEIGHT = 1.0;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private Category category;
    private double weight;

    public CategoryWeight() {
    }

    public CategoryWeight(Category category, double weight) {
        this.category = category;
        this.weight = weight;
    }

    public void adjustWeight(double adjust){
        double newWeight = weight+adjust;
        weight = Math.min(newWeight, MAX_WEIGHT);
        weight = Math.max(MIN_WEIGHT, newWeight);
    }
    
    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CategoryWeight)) {
            return false;
        }
        CategoryWeight other = (CategoryWeight) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.brainstretch.recommend.CategoryWeight[ id=" + id + " ]";
    }
    
}
